// Based off of https://github.com/thijse/Arduino-Libraries/blob/master/CmdMessenger/Examples/ArduinoController/ArduinoController.ino

#include <CmdMessenger.h>

CmdMessenger cmdMessenger = CmdMessenger(Serial);

int IMAGE_WIDTH;

const int VERSION = 2;

enum
{
  kAcknowledge,
  kError,
  kSetImageWidth,
};

void attachCommandCallbacks()
{
  cmdMessenger.attach(OnUnknownCommand);
  cmdMessenger.attach(kSetImageWidth, OnSetImageWidth);
}

void OnUnknownCommand()
{
  cmdMessenger.sendCmd(kError,"Command without attached callback");
}

void OnSetImageWidth()
{
  int width = cmdMessenger.readIntArg();

  if (width > 0)
  {
    IMAGE_WIDTH = width;
  }

  cmdMessenger.sendCmd(kAcknowledge,IMAGE_WIDTH);
}

void setup()
{
  Serial.begin(9600);

  cmdMessenger.printLfCr();

  attachCommandCallbacks();

  String version_info = "sentinel v";

  cmdMessenger.sendCmd(kAcknowledge,version_info + VERSION);
}

void loop()
{
  cmdMessenger.feedinSerialData();
  delay(10);
}


